from abc import ABC, abstractmethod

class Component(ABC):
    def __init__(self, name: str):
        self.name = name

    @abstractmethod
    def add(self, component: 'Component'):
        pass

    @abstractmethod
    def remove(self, component: 'Component'):
        pass

    @abstractmethod
    def display(self, depth: int):
        pass

class Leaf(Component):
    def add(self, component: 'Component'):
        pass

    def remove(self, component: 'Component'):
        pass

    def display(self, depth: int):
        print("  " * depth + self.name)

class Composite(Component):
    def __init__(self, name: str):
        super().__init__(name)
        self._children = []

    def add(self, component: 'Component'):
        self._children.append(component)

    def remove(self, component: 'Component'):
        self._children.remove(component)

    def display(self, depth: int):
        print("  " * depth + self.name)
        for child in self._children:
            child.display(depth + 1)

# Usage
root = Composite("Root")
child1 = Leaf("Leaf1")
child2 = Composite("Composite1")
grandchild = Leaf("Leaf2")

root.add(child1)
root.add(child2)
child2.add(grandchild)

root.display(0)

'''
代码实现：
Root
  Leaf1
  Composite1
    Leaf2
'''